package com.learn.databinding.workwithobservabledataobjects.bindlayoutwithlivedata

import android.content.Context
import android.content.Intent
import androidx.activity.viewModels
import com.exercise.struct.base.BaseDataBindingActivity
import com.learn.databinding.R
import com.learn.databinding.databinding.ActivityBindLayoutWithLiveDataBinding

class BindLayoutWithLiveDataActivity :
    BaseDataBindingActivity<ActivityBindLayoutWithLiveDataBinding>() {

    override val layoutResId: Int
        get() = R.layout.activity_bind_layout_with_live_data

    /**
     * 创建ViewModel对象
     */
    private val mViewModel: BindLayoutWidthLiveDataViewModel by viewModels()

    override fun setToolbar() {
        mToolbar.setTitle("BindLayoutWithLiveData")
    }

    override fun initView() {
        //设置DataBinding的LifecycleOwner
        mDataBinding.lifecycleOwner = this
        //把ViewModel对象绑定到Layout
        mDataBinding.viewModel = mViewModel
    }

    companion object {
        fun start(context: Context) {
            Intent(context, BindLayoutWithLiveDataActivity::class.java)
                .also { context.startActivity(it) }

        }
    }
}